package top.lixunda.ecommerce.server.good.api.entity.vo;

import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;
import top.lixunda.ecommerce.server.good.api.entity.db.FrequentlyQuestionDO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * FQA前端显示数据
 *
 * @author Xumda
 * @version time:2020/1/7 16:07
 */
@SuppressWarnings("WeakerAccess")
@ApiModel("FQA前端实现数据")
@Data
@EqualsAndHashCode(callSuper = true)
public class QuestionVO extends FrequentlyQuestionDO {

    public static QuestionVO fromFrequentlyQuestionDO(FrequentlyQuestionDO frequentlyQuestionDO) {
        if (frequentlyQuestionDO == null) {
            return null;
        }
        QuestionVO questionVO = new QuestionVO();
        BeanUtils.copyProperties(frequentlyQuestionDO, questionVO);
        return questionVO;
    }

    public static List<QuestionVO> fromFrequentlyQuestionDO(List<FrequentlyQuestionDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(item -> {
                    QuestionVO vo = new QuestionVO();
                    BeanUtils.copyProperties(item, vo);
                    return vo;
                })
                .collect(Collectors.toList());
    }

}
